#ifndef _GRO_FONT_NFONT_H__
#define _GRO_FONT_NFONT_H__

#include "NFont.h"

namespace GRO
{

class GRO_Font_NFont : public GRO_Font
{
    public:
    char* buffer;
    NFont font;
    GRO_Font_NFont()
        : buffer(new char[1024])
    {}
    GRO_Font_NFont(NFont* nfont)
        : buffer(new char[1024])
    {
        if(nfont != NULL && nfont->getSurface() != NULL)
            font.load(nfont->getDest(), SDL_ConvertSurface(nfont->getSurface(), nfont->getSurface()->format, SDL_SWSURFACE));
    }
    GRO_Font_NFont(const NFont& nfont)
        : buffer(new char[1024])
    {
        if(nfont.getSurface() != NULL)
            font.load(nfont.getDest(), SDL_ConvertSurface(nfont.getSurface(), nfont.getSurface()->format, SDL_SWSURFACE));
    }

    virtual ~GRO_Font_NFont()
    {
        delete[] buffer;
        SDL_FreeSurface(font.getSurface());
    }
    
    void setFont(const NFont& nfont)
    {
        if(nfont.getSurface() != NULL)
            font.load(nfont.getDest(), SDL_ConvertSurface(nfont.getSurface(), nfont.getSurface()->format, SDL_SWSURFACE));
    }

    void draw(int x, int y, const char* formatted_text, ...)
    {
        if(formatted_text == NULL)
            return;

        va_list lst;
        va_start(lst, formatted_text);
        vsprintf(buffer, formatted_text, lst);
        va_end(lst);
        
        //font.setDest(gui.screen);
        //font.draw(x, y, buffer);
        //x = 200;
        //y = 400;
        font.draw(x, y, "%s", buffer);
    }
    
    void drawf(float x, float y, const char* formatted_text, ...)
    {
        if(formatted_text == NULL)
            return;

        va_list lst;
        va_start(lst, formatted_text);
        vsprintf(buffer, formatted_text, lst);
        va_end(lst);
        
        
        //font.setDest(gui.screen);
        font.draw(x, y, "%s", buffer);
    }

    void drawCenter(int x, int y, const char* formatted_text, ...)
    {
        if(formatted_text == NULL)
            return;

        va_list lst;
        va_start(lst, formatted_text);
        vsprintf(buffer, formatted_text, lst);
        va_end(lst);
        
        //font.setDest(gui.screen);
        font.drawCenter(x, y, "%s", buffer);
    }

    void drawRight(int x, int y, const char* formatted_text, ...)
    {
        if(formatted_text == NULL)
            return;

        va_list lst;
        va_start(lst, formatted_text);
        vsprintf(buffer, formatted_text, lst);
        va_end(lst);
        
        //font.setDest(gui.screen);
        font.drawRight(x, y, "%s", buffer);
    }

    int getHeight(const char* formatted_text = NULL, ...)
    {
        if(formatted_text == NULL)
            return 0;
        va_list lst;
        va_start(lst, formatted_text);
        vsprintf(buffer, formatted_text, lst);
        va_end(lst);
        
        return font.getHeight("%s", buffer);
    }

    int getWidth(const char* formatted_text, ...)
    {
        if(formatted_text == NULL)
            return 0;
        va_list lst;
        va_start(lst, formatted_text);
        vsprintf(buffer, formatted_text, lst);
        va_end(lst);
        
        return font.getWidth("%s", buffer);
    }

    void setSpacing(int LetterSpacing)
    {
        font.setSpacing(LetterSpacing);
    }

    int getSpacing()
    {
        return font.getSpacing();
    }

    void setLineSpacing(int LineSpacing)
    {
        font.setLineSpacing(LineSpacing);
    }

    int getLineSpacing()
    {
        return font.getLineSpacing();
    }

    int getBaseline()
    {
        return font.getBaseline();
    }

    int setBaseline(int Baseline = -1)
    {
        return font.setBaseline(Baseline);
    }
    
    int getAscent(const char character)
    {
        return font.getAscent(character);
    }
    
    int getAscent(const char* formatted_text = NULL, ...)
    {
        if(formatted_text == NULL)
            return 0;
        va_list lst;
        va_start(lst, formatted_text);
        vsprintf(buffer, formatted_text, lst);
        va_end(lst);
        
        return font.getAscent("%s", buffer);
    }
    
    int getDescent(const char character)
    {
        return font.getDescent(character);
    }

    int getDescent(const char* formatted_text = NULL, ...)
    {
        if(formatted_text == NULL)
            return 0;
        va_list lst;
        va_start(lst, formatted_text);
        vsprintf(buffer, formatted_text, lst);
        va_end(lst);
        
        return font.getDescent("%s", buffer);
    }

    int getMaxWidth()
    {
        return font.getMaxWidth();
    }
    
};

}


#endif
